<html>
<head>
<meta charset="UTF-8">
<title>分类基础信息表列表</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
<script type="text/javascript">
    var roleno;
    $(function() {
        menuFuncOp($.getUrlParam('funcOpStr'));
    });

    //根据用户拥有的资源操作权限信息，动态控制按钮
    function menuFuncOp(funcOpStr) {
        if(null != funcOpStr && "" != funcOpStr){
            var linkButtons = document.getElementById("tb").getElementsByClassName("easyui-linkbutton");
            for(var i = 0; i < linkButtons.length; i++){
                if(funcOpStr.indexOf(linkButtons[i].id) == -1){
                    document.getElementById(linkButtons[i].id).style.display = 'none';
                }
            }
        }
    }

	function doAdd(){
		JLEUtil.createModalWin('新增', 'SSubsInfoAdd.html');
	}
	
	function doUpdate() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			JLEUtil.createModalWin('修改', 'SSubsInfoUpdate.html?' + 'subsCode=' + row.subsCode);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doDelete(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					if(row.subsCode=="console"){
						$.messager.alert('提示','根系统不可删除！','info');
					}else{
 						var jsonData = JSON.parse('{'+'"subsCode":"' + row.subsCode + '"'+'}');
						$.restfulDelete('../../api/s/subs/info', jsonData, function(data) {
							$.messager.alert('提示','记录删除成功!','info');
							$('#dg').datagrid('reload');
						});
					}
				}
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doView(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','SSubsInfoView.html?' + '&subsCode=' + row.subsCode);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
    function getRolesNumber(){
        $.ajax({
            type: "POST",
            url: '../../api/s/roles',
            data: {
            },
            success: function(data) {
                roleno=data.rows[0].roleno;
            }
        });
    }
    //创建业务系统根菜单
    function createRootNode() {
        var row = $('#dg').datagrid('getSelected');
        //判断业务系统是否已创建根节点
        $.restfulGet('../../api/s/resource/' + row.subsCode,
            null,
            function(data){
                $.messager.alert('提示','业务系统已是根节点，请勿重复创建','info');
            },
            function (data) {
                var jsonData={
                    resourceid:row.subsCode,
                    cnname:row.subsName,
                    systempk:row.subsCode,
                    parentid:'root',

                };
                $.restfulPostJson('../../api/s/resource', jsonData, function(data) {
                    //资源定义
                    var actionJsondate=JSON.parse('{'+'"descr":"' + '菜单访问' + '"'
                        + ','+'"resourceid":"' + jsonData.resourceid + '"'
                        + ','+'"actid":"' + 'visit' + '"'+'}');
                    $.restfulPostJson('../../api/s/resourceaction', actionJsondate, function(data) {
                    });
                    //资源操作
                    var roleJsondate=JSON.parse('{'+'"roleno":"' + roleno + '"'
                        + ','+'"resourceid":"' + jsonData.resourceid + '"'
                        + ','+'"actIdStr":"' + 'visit' + '"'+'}');
                    console.log("roleno="+roleno);
                    $.restfulPostJson('../../api/s/role/right/save', roleJsondate, function(data) {
                    });

                    $.restfulPostJson('../../api/paas/apps/info', {
                    	"appId": row.subsCode,
						"appCode": row.subsCode,
						"appName": row.appName,
						"archType": "C",
					}, function(data){})

                });
                $.messager.alert('提示','创建根节点成功！','info');
                // $.messager.confirm('跳转提示', '是否要跳转到?', function(r){
                //     if (r){
                //         // $('#tt').tabs('enableTab', '自动流程配置');
                //         addTab("自动流程配置","AutoBpmBaseInfoList.html")
                //     }
                // });
            });
    }


    //创建业务系统批次配置菜单
    function createBatchConf() {
        var row = $('#dg').datagrid('getSelected');
        //判断是否选择一条记录
        if (row){
            //判断业务系统是否是根节点，否则要先创建为根节点
            $.restfulGet('../../api/s/resource/' + row.subsCode,
                null,
                function(data){
                    var row = $('#dg').datagrid('getSelected');
                    var jsonData={
                        resourceid:row.subsCode+"-batchConf",
                        cnname:row.subsName,
						url:'tdp-console/SmcenterIndex.html?subsCode='+row.subsCode,
                        orderid:row.orderId,
                        systempk:'admin',
                        parentid:'PCPZGL',
                    };
                    //判断业务系统是否存在批次配置菜单
                    $.restfulGet('../../api/s/resource/' + jsonData.resourceid,
                        null,
                        function(data){//已存在则提示请勿重复创建
                            $.messager.alert('提示','业务系统批次配置菜单已创建，请勿重复创建！','info');
                        },
                        function(){//查询不存在则创建
                            $.restfulPostJson('../../api/s/resource', jsonData, function(data) {
                                //资源定义
                                var actionJsondate=JSON.parse('{'+'"descr":"' + '菜单访问' + '"'
                                    + ','+'"resourceid":"' + jsonData.resourceid + '"'
                                    + ','+'"actid":"' + 'visit' + '"'+'}');
                                $.restfulPostJson('../../api/s/resourceaction', actionJsondate, function(data) {
                                });
                                //资源操作
                                var roleJsondate=JSON.parse('{'+'"roleno":"' + roleno + '"'
                                    + ','+'"resourceid":"' + jsonData.resourceid + '"'
                                    + ','+'"actIdStr":"' + 'visit' + '"'+'}');
                                $.restfulPostJson('../../api/s/role/right/save', roleJsondate, function(data) {
                                });
                            });
                            $.messager.alert('提示','批次配置菜单创建成功！','info');
                        });
                },
                function (data) {
                    $.messager.alert('提示','业务系统还不是根节点，请先创建根节点','info');
                });
        }else{
            $.messager.alert('提示','请选择一条记录！','info');
        }
    }

	function reloadList(){
		$('#dg').datagrid('reload');
		JLEUtil.closewin();
	};
    $(function () {
        //获取角色列表
        getRolesNumber();
    })
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',title:''" style="height: 40px;">
	<form id="searchForm">
		<table>
			<tr>
				<td>&nbsp;业务系统代码：</td>
				<td><input name="subsCode" id="subsCode"/></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.queryForm('searchForm','dg','../../api/s/subs/infos');">查找</a></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
			</tr>
		</table>
	</form>
</div>
<div data-options="region:'center',split:false">
<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:90%"
			data-options="singleSelect:true,collapsible:true,url:'../../api/s/subs/infos',method:'post'"
			toolbar="#tb"
		title="Load Data" 
		rownumbers="true" pagination="true" pageSize="20">
		<thead>
			<tr>
				<th data-options="field:'subsCode',resizable:true" >业务系统代码</th>
				<th data-options="field:'subsName',resizable:true" >业务系统名称</th>
				<th data-options="field:'subsDataDate',resizable:true" >业务系统数据日期</th>
				<th data-options="field:'subsLastDataDate',resizable:true" >业务系统上一数据日期</th>
				<th data-options="field:'subsLoadDate',resizable:true" >业务系统装数完成日期</th>
				<th data-options="field:'subsBatDate',resizable:true" >业务系统批次完成日期</th>
				<th data-options="field:'batchIdPrefix',resizable:true" >批次编号前缀</th>
				<th data-options="field:'rsvDate',resizable:true" >备用日期</th>
				<th data-options="field:'rsvState',resizable:true" >备用状态</th>
				<th data-options="field:'orderId',resizable:true" >排序字段</th>
			</tr>
		</thead>
	</table>
</div>
<div id="tb" style="padding:1px">
	<div style="margin-bottom:2px">
		<a href="javascript:doAdd()" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="create">新增</a>
		<a href="javascript:doUpdate()" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="modify">修改</a>
		<a href="javascript:doDelete()" class="easyui-linkbutton" iconCls="icon-remove" plain="true" id="delete">删除</a>
		<a href="javascript:doView()" class="easyui-linkbutton" iconCls="icon-ok" plain="true" id="detail">查看</a>
		<a href="javascript:createRootNode()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">创建业务系统根菜单</a>
		<a href="javascript:createBatchConf()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">创建业务系统批次配置菜单</a>
	</div>
</div>
</body>
</html>
